package com.uzai.console.web.tiktok;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.enums.DeviceTypeEnum;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.common.utils.Tools;
import com.uzai.console.dto.device.DeviceQuery;
import com.uzai.console.dto.tiktok.group.tiktokgroup.*;
import com.uzai.console.dto.wechatprivate.wxcontacts.WxContactsRefreshDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.tiktok.TiktokConversationService;
import com.uzai.console.vo.device.DeviceInfoVo;
import com.uzai.console.vo.tiktok.group.tiktokgorup.TiktokConversationVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 抖音群
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "抖音设备群", tags = "抖音设备|抖音设备群")
@ApiSort(6)
@RestController
public class TiktokConversationController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(TiktokConversationController.class);

    @Autowired
    private TiktokConversationService tiktokConversationService;
    @Autowired
    private DeviceService deviceService;

    @ApiOperation(value = "查询抖音设备群列表", notes = "查询抖音设备列表", response = TiktokConversationVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/tiktokConversation/findTiktokConversationList")
    public Object findTiktokConversationList(@RequestBody TiktokConversationQuery tiktokConversationQuery){
        return tiktokConversationService.findTiktokConversationList(tiktokConversationQuery);
    }

    @ApiOperation(value = "查询抖音设备群机器人列表", notes = "查询抖音设备群机器人列表", response = DeviceInfoVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/tiktokConversation/findDeviceList")
    public Object findDeviceList(){
        DeviceQuery deviceQuery = new DeviceQuery();
        deviceQuery.setDeviceType(DeviceTypeEnum.TIKTOK.getKey());
        deviceQuery.setMerId(getLoginInfo().getMerId());
        return deviceService.findDeviceList(deviceQuery);
    }

    @SystemLogType(model = SystemModelEnum.TiktokConversation, type = OperationTypeEnum.SENDMESSAGE)
    @ApiOperation(value = "抖音设备群发送消息", notes = "抖音设备群发送消息")
    @ApiOperationSupport(order = 4)
    @PostMapping("/tiktokConversation/sendMessage")
    public Object sendMessage(@RequestBody TiktokConversationSendMessageDto tiktokConversationSendMessageDto){
        tiktokConversationService.sendMessage(tiktokConversationSendMessageDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.TiktokConversation, type = OperationTypeEnum.SENDMESSAGE)
    @ApiOperation(value = "抖音设备群批量发送消息", notes = "抖音设备群批量发送消息")
    @ApiOperationSupport(order = 4)
    @PostMapping("/tiktokConversation/sendMessageBatch")
    public Object sendMessage(@RequestBody TiktokConversationSendMessageBatchDto tiktokConversationSendMessageBatchDto){
        tiktokConversationService.batchSendMessage(tiktokConversationSendMessageBatchDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.TiktokConversation, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "抖音设备群修改管理方案", notes = "抖音设备群修改管理方案")
    @ApiOperationSupport(order = 5)
    @PostMapping("/tiktokConversation/updateManagePlan")
    public Object updateManagePlan(@RequestBody TiktokConversationUpdateManagePlanDto tiktokConversationUpdateManagePlanDto){
        tiktokConversationService.updateManagePlan(tiktokConversationUpdateManagePlanDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.TiktokConversation, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "抖音设备群批量修改管理方案", notes = "抖音设备群批量修改管理方案")
    @ApiOperationSupport(order = 5)
    @PostMapping("/tiktokConversation/batchUpdateManagePlan")
    public Object batchUpdateManagePlan(@RequestBody TiktokConversationBatchUpdateManagePlanDto tiktokConversationBatchUpdateManagePlanDto){
        tiktokConversationService.batchUpdateManagePlan(tiktokConversationBatchUpdateManagePlanDto);
        return true;
    }

    @ApiOperation(value = "查询已经配置了管理方案的抖音设备群列表", notes = "查询已经配置了管理方案的抖音设备群列表", response = TiktokConversationVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/tiktokConversation/findtiktokConversationManagePlanList")
    public Object findWxqGroupManagePlanList(@RequestBody TiktokConversationQuery tiktokConversationQuery){
        tiktokConversationQuery.setManagePlanIdFlag(1);//开启过滤未配置管理方案
        //如果开启了ConversationId去重，则不需要开启未配置管理方案过滤
        if(Tools.getInteger(tiktokConversationQuery.getConversationIdDistinctFlag()).intValue() == 1){
            tiktokConversationQuery.setManagePlanIdFlag(null);//不需要开启过滤未配置管理方案
        }
        return tiktokConversationService.findTiktokConversationList(tiktokConversationQuery);
    }

    @SystemLogType(model = SystemModelEnum.DeviceWechatWxContacts, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "更新抖音设备群", notes = "更新抖音设备群")
    @ApiOperationSupport(order = 7)
    @PostMapping("/tiktokConversation/refreshTiktokConversation")
    public Object refreshTiktokConversation(@RequestBody TiktokConversationRefreshDto tiktokConversationRefreshDto){
        tiktokConversationService.refreshTiktokConversation(tiktokConversationRefreshDto);
        return true;
    }

}
